package cn.itcast.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import cn.itcast.dao.IEmployeeDao;
import cn.itcast.entity.Employee;

public class EmployeeDao extends BaseDao<Employee> implements IEmployeeDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> getAll(String employeeName) {
		Session session = getSessionFactory().getCurrentSession();
		Query q = session.createQuery("from Employee where empName like ?");
		q.setParameter(0, "%" +employeeName + "%");
		return q.list();
	}

	@Override
	public Employee findById(int id){
		String hql = "from Employee e left join fetch e.dept where e.id=?";
		Session session = getSessionFactory().getCurrentSession();
		Query q = session.createQuery(hql);
		q.setParameter(0, id);
		return (Employee) q.uniqueResult();
	}

}
